import { Controller } from "../../mvc/core/Controller";
import { ICampChangeController } from "./interfaces/ICampChangeController";
import { IView } from "../../mvc/interfaces/IView";
import { CampChangeModule } from "../../../modules/CampChangeModule";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { ServerCommand } from "../mvc/ServerCommand";
import { DataEvent } from "../events/DataEvent";
import { NpcEffectRule } from "../rules/NpcEffectRule";
import { GameProxy } from "../mvc/GameProxy";
import { ClockManager } from "../manager/ClockManager";
import { CampChangeData } from "../view/change/CampChangeData";
import { Language } from "../../../extend/language/Language";
import { Alert } from "../../../com/mui/controls/Alert";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SCampCivilizationInfo } from "../../../Message/Game/SCampCivilizationInfo";
import { SPlayerCampChangeInfo } from "../../../Message/Game/SPlayerCampChangeInfo";
import { Cache } from "../cache/Cache";
import { GameDefConfig } from "../resource/GameDefConfig";
import { MsgManager } from "../manager/MsgManager";
import { SActiveToClient } from "../../../Message/Public/SActiveToClient";
import { ICampChangeModule } from "../../../modules/interfaces/ICampChangeModule";
type int = number;
//class CampChangeController
    
    export  class CampChangeController extends Controller implements ICampChangeController
    {
       

        protected /* override */ initView(): IView
        {
            if (this._campChangeModule == null) 
            {
                this._campChangeModule = new CampChangeModule();
            }
            return this._campChangeModule;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.CampChangeOpen, this.onCampChangeOpenHandler);
            Dispatcher.addEventListener(EventName.CampToChange, this.onCampToChangeHandler);
            Dispatcher.addEventListener(EventName.CampChangeGetCdSuccess, this.onGetCdSuccessHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateCivilizationInfo, this.onCivilizationInfoHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateChangeCampSuccess, this.onChangeCampSuccessHandler);
            NetDispatcher.addCmdListener(ServerCommand.ActiveTypeChangeCampNoConditions, this.onChangeCampNoConditionsHandler);
            return;
        }

        /* internal  */onCampChangeOpenHandler(arg1: DataEvent): void
        {
            var loc3=null;
            view.show();
            NpcEffectRule.registDialogEffectWindow(view);
            GameProxy.roleProxy.canChangeCampAfterDays();
            var loc1=ClockManager.instance.nowDate;
            var loc2=CampChangeData.civilizationInfo.openDt;
            if (loc1.time < loc2.time) 
            {
                loc3 = Language.getStringByParam(36030, loc2.fullYear, loc2.month + 1, loc2.date);
                Alert.show(loc3, null, Alert.OK, null);
            }
            return;
        }

        /* internal  */onCampToChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.roleProxy.changeCamp(loc1);
            return;
        }

        /* internal  */onGetCdSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data;
            var loc2=loc1.days as int;
            var loc3=loc1.campNumChanged as Map<any, any> /* flash.utils.Dictionary */;
            var loc4=loc1.isActived as Boolean;
            CampChangeData.cdDays = loc2;
            CampChangeData.campNumChanged = loc3;
            CampChangeData.isActived = loc4;
            if (this._campChangeModule && !this._campChangeModule.isHide) 
            {
                this._campChangeModule.updateCdInfo();
            }
            return;
        }

        /* internal  */onCivilizationInfoHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SCampCivilizationInfo;
            CampChangeData.civilizationInfo = loc1;
            if (this._campChangeModule && !this._campChangeModule.isHide) 
            {
                this._campChangeModule.updateCampChangeInfo();
            }
            return;
        }

        /* internal  */onChangeCampSuccessHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SPlayerCampChangeInfo;
            GameProxy.roleProxy.canChangeCampAfterDays();
            Cache.instance.role.entityInfo.camp = loc1.goalCamp;
            Dispatcher.dispatchEvent(new DataEvent(EventName.CampChangeSuccess, loc1.goalCamp));
            var loc2=GameDefConfig.instance.getECamp(loc1.goalCamp);
            MsgManager.showRollTipsMsg(Language.getStringByParam(36031, loc2));
            view.hide();
            return;
        }

        /* internal  */onChangeCampNoConditionsHandler(arg1: SActiveToClient): void
        {
            var loc1=false;
            if (arg1) 
            {
                loc1 = cache.active.isActiveInEffectByInfo(arg1);
                CampChangeData.isInActived = loc1;
                if (this._campChangeModule && !this._campChangeModule.isHide) 
                {
                    this._campChangeModule.updateCampChangeInfo();
                }
            }
            return;
        }

        private /* var */_campChangeModule: ICampChangeModule;
    }
